<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 2017/6/13
 * Time: 下午11:06
 */
class RankingController extends AdminBaseController
{

    public function server(){
        $this->setTitle('服务器货币消耗排行');

        $filter = new PubFilter();
        $chart  = new PubChart();
        $grid   = new PubGrid();

        $coinTypes = CoinService::getCoinType();
        $filter->addOsFilter()
            ->addServerFilter(false)
            ->addFilter('date', 'input', '日期', array('value' => date('Y-m-d',strtotime('yesterday')), 'date' => 'day'))
            ->addFilter('coinType', 'radio', '货币', array('options' => $coinTypes, 'value' => key($coinTypes)))
            ->addFilter('state', 'hidden', '', array('value' => 'ALL'))
            ->addExport();


        $params = $filter->get();
        $header = RankingService::serverHeader();
        $data   = RankingService::serverData($params);

        if($filter->isExport()){
            $filename = LibExcel::getFilename('服务器货币消耗排行', $params);
            LibExcel::exportCsv($header, $data, $filename);
        }else {
            $grid->addGrid($header, $data, array(
                'order' => array('GetNumber', 'desc'),
                'showAll' => 1,
            ));
        }

        $this->out['filter'] = $filter->show();
        $this->out['grid'] = $grid->show();
    }

}